package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.BaseConfig;
import com.briup.jz.bean.BaseConfigExample;

import com.briup.jz.dao.BaseConfigMapper;
import com.briup.jz.service.IBaseConfigService;
import com.briup.jz.utils.CustomerException;

@Service
public class BaseConfigServiceImpl implements IBaseConfigService{
	@Autowired
	private BaseConfigMapper baseconfigMapper;

	@Override
	public void saveOrUpdate(BaseConfig baseconfig) throws CustomerException {
		if(baseconfig.getId()!=null) {
			baseconfigMapper.updateByPrimaryKey(baseconfig);
		} else {
//			// 判断是否有同名的分类，如果有抛出异常
//		BaseConfigExample example = new BaseConfigExample();
//		example.createCriteria().andIdEqualTo(baseconfig.getId());
//			List<BaseConfig> list = baseconfigMapper.selectByExample(example);
//			if(list.size()>0) {
//				throw new CustomerException("同名的Name已存在");
//			}
			baseconfigMapper.insert(baseconfig);
			
		}
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<BaseConfig> query(String name) {
		
		// TODO Auto-generated method stub
		BaseConfigExample example = new BaseConfigExample();
		if(name!=null){
			example.createCriteria().andNameLike("%"+name+"%");
		}
		List<BaseConfig> list = baseconfigMapper.selectByExample(example);
		return list;
		
		
	}
	@Override
	public void deleteById(long id) throws CustomerException {
		BaseConfig baseconfig= baseconfigMapper.selectByPrimaryKey(id);
		if(baseconfig == null) {
			throw new CustomerException("要删除的分类信息不存在");
		}
		baseconfigMapper.deleteByPrimaryKey(id);
		
	}
	
}
